#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time    : 2021/12/5 11:15 下午
# @Author  : WangZhixing
from networkx import DiGraph

from .arch import from_rsf
from .a2a import a2a
from .c2c import c2c_cvg
from .mojofm import mojofm
from .turbo_mq.turbo_mq import norm_turbo

import os
def Bash(file,gr_path,dep_rsf):
    if gr_path==None:
        fileg=os.path.join(os.path.dirname(os.path.abspath(__file__)),"ground-truth","bash_gt.rsf")
    else :
        fileg=gr_path

    recovered = from_rsf(file)
    ground_truth = from_rsf(fileg)
    a2am=round(100*a2a(recovered, ground_truth))
    c2c0_5=round(100*c2c_cvg(recovered, ground_truth, threshold=0.5))
    c2c0_3=round(100*c2c_cvg(recovered, ground_truth, threshold=0.3))
    c2c0_1=round(100*c2c_cvg(recovered, ground_truth, threshold=0.1))

    mojofmm = mojofm(arc_file_1=file, arc_file_2=fileg)

    if dep_rsf == None:
        t = 0
    else:
        dep_graph = DiGraph()
        with open(dep_rsf, "r") as f:
            lines = f.readlines()
            for line in lines:
                tokens = line.strip().split()
                if len(tokens) == 3:
                    dep_graph.add_edge(tokens[1], tokens[2])
                elif len(tokens) == 2:
                    dep_graph.add_edge(tokens[0], tokens[1])

        t = round(100*norm_turbo(arch=recovered, mdg=dep_graph))

    print("Bash项目的指标")
    print("a2a:"+str(a2am))
    print("c2c0_5：" + str(c2c0_5))
    print("c2c0_3：" + str(c2c0_3))
    print("c2c0_1：" + str(c2c0_1))
    print("mojofm：" + str(mojofmm))
    print("norm_turbo：" + str(t))

    return len(recovered),a2am,c2c0_5,c2c0_3,c2c0_1,mojofmm,t

